program AdditionOfPolynomials;

{$APPTYPE CONSOLE}

type
  pelement=^element;
  element= record
    a, b, c, d:integer;
    next: pelement;
  end;

var
  i, j, m, n: integer;
  fin: textFile;
  head, h, leag, l: pelement;

begin
  assign(fin, 'input.txt');
  reset(fin);
  readln(fin, n);
  new(head);
  h:=head;
  for i:=0 to 2*n-1 do
  begin
    if ((i mod 2)=0) then
      read(fin,head^.a)
    else
    begin
      if (i<(2*n-1)) then
      begin
        read(fin, head^.d);
        new(head^.next);
        head:=head^.next;
      end else
        read(fin, head^.d);
      end;
  end;
  head:=nil;
  writeln;
  readln(fin, m);
  new(leag);
  l:=leag;
  for i:=0 to 2*m-1 do
  begin
    if ((i mod 2)=0) then
      read(fin,leag^.b)
    else
    begin
      if (i<(2*m-1)) then
      begin
        read(fin, leag^.c);
        new(leag^.next);
        leag:=leag^.next;
      end
      else
        read(fin, leag^.c);
      end;
  end;
  leag:=nil;
  if (n<m) then
  begin
    while (h<> nil) do
    begin
      if (h^.d>l^.c) then
      begin
        write('+',h^.a);
        for i:=0 to h^.d-1 do
          write('*x');
        h:=h^.next;
      end else
      begin
        if (h^.d=l^.c) then
        begin
          write('+', h^.a+l^.b);
          for i:=0 to h^.d-1 do
            write('*x');
          h:=h^.next;
          l:=l^.next;
        end else
        begin
          write('+',l^.b);
          for i:=0 to l^.c-1 do
            write('*x');
          l:=l^.next;
        end;
      end;
    end;
    if (l<>nil) then
    begin
      while (l<>nil) do
      begin
        write('+',l^.b);
        for i:=0 to l^.c-1 do
          write('*x');
        l:=l^.next;
      end;
    end;
  end else
  begin
    while (l<> nil) do
    begin
      if (h^.d>l^.c) then
      begin
        write('+',h^.a);
        for i:=0 to h^.d-1 do
          write('*x');
        write('+');
        h:=h^.next;
      end else
      begin
        if (h^.d=l^.c) then
        begin
          write('+',h^.a+l^.b);
          for i:=0 to h^.d-1 do
            write('*x');
          h:=h^.next;
          l:=l^.next;
        end else
        begin
          write('+',l^.b);
          for i:=0 to l^.c-1 do
            write('*x');
          l:=l^.next;
        end;
      end;
    end;
    if (h<>nil) then
    begin
      while (h<>nil) do
      begin
        write('+',h^.a);
        for i:=0 to h^.d-1 do
          write('*x');
        h:=h^.next;
      end;
    end;
  end;
  readln;
  end.

